package com.vchangyi.springboot.controller;

import com.vchangyi.springboot.common.utils.IMOOCJSONResult;
import com.vchangyi.springboot.pojo.UserEntity;
import com.vchangyi.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author maguoq
 * @Date 2023年05月31日 15:52
 */
@RestController
@RequestMapping("/api")
public class ApiController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public IMOOCJSONResult list(){
        List<UserEntity> list = userService.list();
        return IMOOCJSONResult.ok(list);
    }

    @PostMapping("/save")
    public IMOOCJSONResult save(@RequestBody UserEntity user){
        userService.saveOrUpdate(user);
        return IMOOCJSONResult.ok();
    }

    @PostMapping("/batchSave")
    public IMOOCJSONResult BatchSave(@RequestBody List<UserEntity> users){
        userService.saveBatch(users);
        return IMOOCJSONResult.ok();
    }

}